﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExamText
{
    public partial class Res : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var user = TextBox1.Text.Trim();
            var pwd = TextBox2.Text.Trim();
            string sql = "select * from Users where Username='" + user + "'";

            DataTable table = DbHelper.GetDataTable(sql);

            if (table.Rows.Count == 1)
            {
                Label4.Text = "用户名已注册过，不需要再进行注册";
                Label4.Visible = true;
            }
            else{
                sql = "insert into Users(Username,Password) values('" + user + "','" + pwd + "')";
                var res = DbHelper.UpdateData(sql);

                if (res == 1)
                {
                    Response.Write("<script>alert('注册成功，请返回登入')</script>");
                }
                else
                {
                    Response.Write("<script>alert('注册失败')</script>");
                }
            }
        }
    }
}